package com.team.dao.impl;
import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 管理模块Dao实现类
 */
import com.team.dao.AdminiStrationDao;
import com.team.entity.Announcement;
import com.team.entity.CapitalReport;
import com.team.entity.DutyOfficer;
import com.team.entity.Equipment;
import com.team.entity.RepairMan;
@Repository
public class AdminiStrationImpl implements AdminiStrationDao {
	@Autowired
	private SessionFactory sessionFactory;
	//保存值班人员信息
	public void savedutyOfficer(DutyOfficer dutyOfficer) {
		this.sessionFactory.getCurrentSession().save(dutyOfficer);
		
	}

	//列出所有值班人员信息
	public List<DutyOfficer> listAllDutyOfficer() {
		// TODO Auto-generated method stub
		List<DutyOfficer> dutyOfficers=this.sessionFactory.getCurrentSession().createQuery("from DutyOfficer").list();

		return dutyOfficers;
	}

	//保存维修人员信息
	public void savedepairMan(RepairMan repairMan) {
		// TODO Auto-generated method stub
		this.sessionFactory.getCurrentSession().save(repairMan);
		
	}
      //列出所有维修人员
	@Override
	public List<RepairMan> listAllRepairMan() {
		// TODO Auto-generated method stub
		List<RepairMan> repairMan=this.sessionFactory.getCurrentSession().createQuery("from RepairMan").list();

		return repairMan;
	}
     
	//查询单个维修人员对象
	@Override
	public RepairMan finRepairManById(int id) {
		// TODO Auto-generated method stub
		
		String hql="from RepairMan where id=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, id);
		RepairMan repairMan=(RepairMan) query.uniqueResult();
		
		return repairMan;
	}
   //修改维修人员信息
	@Override
	public void updateRepairMan(RepairMan repairMan) {
		// TODO Auto-generated method stub
		this.sessionFactory.getCurrentSession().update(repairMan);
		
	}
    //删除维修人员信息
	@Override
	public void delRepairMan(RepairMan repairMan) {
		String hql="delete RepairMan where id=:id";
		this.sessionFactory.getCurrentSession().delete(repairMan);
		
	}
    //保存通知公告信息
	@Override
	public void saveAnnouncement(Announcement Announcement) {
		// TODO Auto-generated method stub
		this.sessionFactory.getCurrentSession().save(Announcement);
		
	}
    //列出所有通知公告
	@Override
	public List<Announcement> listAllAnnouncement() {
		// TODO Auto-generated method stub
		List<Announcement> announcement=this.sessionFactory.getCurrentSession().createQuery("from Announcement").list();
		
		return announcement;
	}

	@Override
	public Announcement finAnnouncementById(int id) {
		// TODO Auto-generated method stub
		String hql="from Announcement where id=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, id);
		Announcement announcement=(Announcement) query.uniqueResult();
		return announcement;
	}

	@Override
	public List<Equipment> selectEquipmentBystatus() {
		// TODO Auto-generated method stub
		String hql="from  Equipment where status=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, "故障");
		List<Equipment> Equipments=query.list();
		
		
		return Equipments;
	}

	@Override
	public void equipmentok(int id) {
		// TODO Auto-generated method stub
		System.out.println("进入方法了吗？");
		String hql="update Equipment set status=?,description=? where id=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		String a="正常";
		query.setParameter(0, a);
		query.setParameter(1, "无");
		query.setParameter(2, id);
		query.executeUpdate();
		
	}
     //查询月度报表
	@Override
	public List<CapitalReport> listMonthPeport(int month, int pagenum) {
		// TODO Auto-generated method stub
		String hql="from CapitalReport where month=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, month);
		query.setFirstResult(pagenum*15);
		query.setMaxResults(15);
		List<CapitalReport> capitalReports=query.list();
		return capitalReports;
	}
     //保存报表
	@Override
	public void saveCapitalReport(CapitalReport capitalReport) {
		// TODO Auto-generated method stub
		this.sessionFactory.getCurrentSession().save(capitalReport);
		
	}
     //查询季度报表
	@Override
	public List<CapitalReport> listSeasonPeport(String season, int pagenum) {
		// TODO Auto-generated method stub
		String hql="from CapitalReport where season=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, season);
		query.setFirstResult(pagenum*15);
		query.setMaxResults(15);
		List<CapitalReport> capitalReports=query.list();
		return capitalReports;
		
	}
    //查询年度报表
	@Override
	public List<CapitalReport> listYearPeport(int year, int pagenum) {
		// TODO Auto-generated method stub
		String hql="from CapitalReport where year=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, year);
		query.setFirstResult(pagenum*15);
		query.setMaxResults(15);
		List<CapitalReport> capitalReports=query.list();
		return capitalReports;
	}

	
}
